/*
 * @(#)BbsSignRankController.java 2019年9月29日 下午4:05:41
 * Copyright 2019 zmr, Inc. All rights reserved. 
 * PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.dev.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.dev.bbs.bean.RankCommentArt;
import com.dev.bbs.bean.RankCommentUser;
import com.dev.bbs.bean.RankSign;
import com.dev.bbs.service.IBbsCommentService;
import com.dev.bbs.service.IBbsUserSignService;
import com.dev.common.utils.RedisUtils;

/**
 * <p>File：BbsSignRankController.java</p>
 * <p>Title: </p>
 * <p>Description:</p>
 * <p>Copyright: Copyright (c) 2019 2019年9月29日 下午4:05:41</p>
 * <p>Company: zmrit.com </p>
 * @author zmr
 * @version 1.0
 */
@Controller
@RequestMapping("rank")
public class BbsRankController
{
    private static final String RANK_SING_KEY     = "rank_sign_key";

    private final static String RANK_COMMENT_USER = "rank_comment_user";

    private final static String RANK_COMMENT_ART  = "rank_comment_art";

    @Autowired
    private IBbsUserSignService userSignService;

    @Autowired
    private IBbsCommentService  commentService;

    @GetMapping("sign")
    @ResponseBody
    public String top()
    {
        String signRank = (String) RedisUtils.get(RANK_SING_KEY);
        if (null == signRank)
        {
            List<List<RankSign>> rank = userSignService.getSignRank();
            if (null != rank)
            {
                signRank = JSON.toJSONString(rank);
                RedisUtils.set(RANK_SING_KEY, signRank, 5 * 60);
            }
        }
        return signRank;
    }

    /**
     * 回帖榜
     * @return
     * @author zmr
     */
    @GetMapping("comment/user")
    @ResponseBody
    public String commentUser()
    {
        String obj = (String) RedisUtils.get(RANK_COMMENT_USER);
        if (null == obj)
        {
            List<RankCommentUser> rank = commentService.getRankCommentUser();
            if (null != rank)
            {
                obj = JSON.toJSONString(rank);
                RedisUtils.set(RANK_COMMENT_USER, obj, 30 * 60);
            }
        }
        return obj;
    }

    /**
     * 热议榜
     * @return
     * @author zmr
     */
    @GetMapping("comment/art")
    @ResponseBody
    public String commentArt()
    {
        String obj = (String) RedisUtils.get(RANK_COMMENT_ART);
        if (null == obj)
        {
            List<RankCommentArt> rank = commentService.getRankCommentArt();
            if (null != rank)
            {
                obj = JSON.toJSONString(rank);
                RedisUtils.set(RANK_COMMENT_ART, obj, 30 * 60);
            }
        }
        return obj;
    }
}
